<?php

class RL_Principal_Session_Store extends RL_Principal_Storage
/**

	Хранилище профилей принципала, основанная на $_SESSION.

	PrincipalStorage_Store( &$principal )
			- $principal       -- к какому принципалу прикрепляться

	-------------------

	Суть структуры:
		* каждый профиль -- объект типа fuser

================================================================== v.1 (sibiryakov@gmail.com)
 */
{
	public function __construct( RL_Principal $principal )
	{
		parent::__construct( $principal );
		session_start();
	}

	public function loadById($oid)
	{
		$profile = false;
		if (isset($_SESSION['principal']['objects'][$oid])) {
			$profile = $_SESSION['principal']['objects'][$oid];
			$profile = array_merge($res, array("user_id"=>$oid));
		}

		return $profile;
	}
	public function loadByDigest($digest)
	{
		$res = false;
		if (isset($_SESSION['principal']['digest'][$digest])) {
			$digest_row = $_SESSION['principal']['digest'][ $digest ];
			$res = $this->loadById($digest_row['oid']);
		}

		return $res;
	}
	public function loadByLogin($login, $realm = NULL)
	{
		$res = false;
		if (isset($_SESSION['principal']['login'][$login])) {
			$login_row = $_SESSION['principal']['login'][$login];
			$res = $this->loadById($login_row['oid']);
		}

		return $res;
	}

	public function setStoredPassword( $user_data, $new_invariant )
	{
	  $login = $user_data["login"];
		$realm = $user_data["realm"];
		$oid = $user_data['user_id'];

		$_SESSION['principal']['login'][$login] = array('oid' => $oid);
		$_SESSION['principal']['objects'][$oid] = $user_data;
		return true;
	}
	public function setStoredDigest ($user_data, $digest)
	{
	  $login = $user_data["login"];
		$oid = $user_data['user_id'];

		$_SESSION['principal']['digest'][$digest] = array('oid' => $oid);
		$_SESSION['principal']['objects'][$oid] = $user_data;
		return $user_data;
	}
	protected function _setLoginDatetime( $user_data, $datetime )
	{
	/*
		 $login = $user_data["login"];
		 $realm = $user_data["realm"];
		 $dt = date("Y-m-d H:i:s", $datetime );
		 $sql = "update ".$this->db_table.
						" set login_datetime = ".$this->rh->ctx->db->Quote($dt).
						" where ".
						"     login=".$this->rh->ctx->db->Quote($login).
						" and realm=".$this->rh->ctx->db->Quote($realm);
		 $this->rh->ctx->db->Query( $sql );
	 */
		return true;
	}
}


?>
